<template>
  <div>
      <el-card class='padd'>
        <el-row>
          <el-col :span='6'>
            打包任务号：{{form.code}}
          </el-col>
          <el-col :span='6'>
            订单数量：{{form.orderQuantity}}
          </el-col>
          <el-col :span='6'>
            包裹数量：{{form.packageQuantity}}
          </el-col>
          <el-col :span='6'>
            商品数量：{{form.goodsQuantity}}
          </el-col>
        </el-row>
      </el-card>
      <el-card class='padd'>
        <div style='margin-bottom:15px'>
          <el-table
            border
            ref="topSingleTable"
            :data="topData"
            height='380px'
            highlight-current-row
            @current-change="handleCurrentChange"
            style="width: 100%;height:300px"
          >
            <el-table-column property="prepackagedCode" label="打包单号" v-if='type && show === 1'> </el-table-column>
            <el-table-column property="code" label="打包单号" v-if='type && show === 0'> </el-table-column>
            <el-table-column property="orderNum" label="作业顺序"> </el-table-column>
            <el-table-column property="planPackQuantity" label="包裹数"> </el-table-column>
            <el-table-column property="deliveryCode" label="订单号" v-if='!type'> </el-table-column>
            <el-table-column property="carrierName" label="承运商"> </el-table-column>
            <el-table-column property="waybillCode" label="运单号"> </el-table-column>
            <el-table-column property="isvCode" label="ISV单号"> </el-table-column>
            <el-table-column property="goodsSortQuantity" label="商品种数"> </el-table-column>
            <el-table-column property="totalNum" label="商品数量"> </el-table-column>
            <el-table-column property="packQuantity" label="打包数量"> </el-table-column>
          </el-table>
        </div>
        <el-table
          border
          ref="bomSingleTable"
          :data="bomData"
          height='360px'
          highlight-current-row
        >
          <el-table-column type="index" width="50"/>
          <el-table-column property="goodsName" label="商品名称"/>
          <el-table-column property="goodCode" label="商品编码"/>
          <el-table-column property="goodsBarCode" label="商品条码"/>
          <el-table-column property="goodsUnitName" label="单位"/>
          <el-table-column property="spec" label="规格"/>
          <el-table-column property="gmtManufacture" label="生产日期"/>
          <el-table-column property="combinationQuantity" label="计划数量"/>
          <el-table-column property="packQuantity" label="打包数量"/>
        </el-table>
      </el-card>
  </div>
</template>
<script>
import { packTaskIng,queryItemByDeliveryCode } from '@/api/packManagement/prePackaged'
export default{
  data(){
    return{
      form:{},
      topData:[],
      bomData:[],
      type :true,
      show: ''
    }
  },
  created(){
    let obj = this.$route.query
    this.query(obj.code)
    this.show = obj.show
  },
  methods:{
    handleCurrentChange(val){
      // if(this.type)return
      // this.$refs.topSingleTable.setCurrentRow(val)
      // queryItemByDeliveryCode(val.packTaskItemVOList[0].deliveryCode).then(req=>{
      //   this.bomData = req.data
      // })
      if(this.$route.query.type != 'prepackaged'){
        this.$refs.topSingleTable.setCurrentRow(val)
        queryItemByDeliveryCode(val.code,this.form.code).then(req=>{
          this.bomData = req.data
        })
      }

    },
    query(code){
      packTaskIng(code).then(res=>{
        this.form = res.data
        this.topData = res.data.packTaskItemVOList
        this.bomData = res.data.deliveryItemWithDistributionVOList
        // if(res.data.prepackaged === 0){
        //   this.type === true
        //   this.topData = res.data.packTaskItemVOList
        //   this.$refs.topSingleTable.setCurrentRow(res.data.packTaskItemVOList[0]);
          // queryItemByDeliveryCode(res.data.packTaskItemVOList[0].deliveryCode).then(req=>{
        //     this.bomData = req.data
        //     console.log("this.bomData",this.bomData);
        //     for (let i = 0; i < this.bomData.length; i++) {
        //       this.bomData[i].planPackQuantity = 1
        //       if(res.data.status === 'waiting') {
        //         this.bomData[i].packQuantity = 0
        //       } else if(res.data.status === 'completed'){
        //         this.bomData[i].packQuantity = 1
        //       }
        //     }
          // })
        // }else{
        //   this.type === false
        //   this.topData = res.data.packTaskItemVOList
        //   this.bomData = res.data.deliveryItemWithDistributionVOList
        //   if(res.data.status === 'waiting'){
        //     for (let i = 0; i < this.topData.length; i++) {
        //       this.topData[i].packQuantity = 0
        //     }
        //   }else if(res.data.status === 'completed'){
        //     for (let i = 0; i < this.topData.length; i++) {
        //       this.topData[i].packQuantity = 1
        //     }
        //   }
        // }

      })
    },
  }
}
</script>
<style>
.padd{
  margin: 10px;
}
.top{
  margin-bottom: 15px;
  height: 100%;
}
</style>
